{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5161141d-313d-4df0-8e43-e923154575d7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello世界这是一个测试1234全角字符\n"
     ]
    }
   ],
   "source": [
    "import re\n",
    "\n",
    "def clean_string(s):\n",
    "    # 将全角字符转换为半角\n",
    "    s = ''.join([chr(ord(c) - 0xFEE0) if 0xFF01 <= ord(c) <= 0xFF5E else c for c in s])\n",
    "\n",
    "    # 只保留数字、字母和中文字符\n",
    "    s = re.sub(r'[^0-9a-zA-Z\\u4e00-\\u9fff]', '', s)\n",
    "\n",
    "    # 转为小写\n",
    "    return s.lower()\n",
    "\n",
    "# 示例\n",
    "input_string = \"Hello, 世界! 这是一个测试 1234【全角字符】\"\n",
    "cleaned_string = clean_string(input_string)\n",
    "print(cleaned_string)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5e221d28-4167-48da-9e55-c7a08ba16088",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "有效的 ISSN/eISSN: ['1682-1750', '16821750', '1234-5678', '12345678', '1682-175X', '1682175x', '1234567X']\n"
     ]
    }
   ],
   "source": [
    "import re\n",
    "\n",
    "def is_valid_issn(issn):\n",
    "    # 正则表达式匹配 ISSN/eISSN 格式，忽略大小写\n",
    "    pattern = r'^(?:\\d{4}-\\d{3}[\\dX]|\\d{7}[\\dX]|\\d{8})$'\n",
    "    return bool(re.match(pattern, issn, re.IGNORECASE))\n",
    "\n",
    "# 示例\n",
    "issns = [\"1682-1750\", \"16821750\", \"1234-5678\", \"12345678\", \"1682-175X\", \"1682175x\", \"1234567X\", \"abcd-efgh\"]\n",
    "\n",
    "# 筛选有效 ISSN/eISSN\n",
    "valid_issns = [issn for issn in issns if is_valid_issn(issn)]\n",
    "\n",
    "print(\"有效的 ISSN/eISSN:\", valid_issns)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "5902287b-57ea-4303-a273-ba0b8d75abb0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "21A\n"
     ]
    }
   ],
   "source": [
    "import re\n",
    "\n",
    "\n",
    "def deal_num_strs(input_str):\n",
    "    number_list = re.findall(r'\\d+', input_str)\n",
    "    transformed_numbers = [str(int(num)) for num in number_list]\n",
    "    \n",
    "    # 替换原字符串中的数字为转换后的数字\n",
    "    for num, transformed_num in zip(number_list, transformed_numbers):\n",
    "        input_str = input_str.replace(num, transformed_num)\n",
    "    return input_str\n",
    "\n",
    "def deal_num(strs):\n",
    "    strs = strs.replace(\"-\",\"_\").replace(\".\",\"_\").upper()\n",
    "    if strs.find(\"_\") > -1:\n",
    "        start,end = strs.split(\"_\")\n",
    "        start = deal_num_strs(start)\n",
    "        end =  deal_num_strs(end)\n",
    "        strs = start+\"_\"+end\n",
    "    else:\n",
    "        strs = deal_num_strs(strs)\n",
    "\n",
    "    return strs\n",
    " \n",
    "print(deal_num(\"21A\"))   \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "649fcabe-ecff-46d0-8f67-f28d49248763",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>6S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>T03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>04b</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>37A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>650</th>\n",
       "      <td>Z0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>651</th>\n",
       "      <td>SH</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>652</th>\n",
       "      <td>07A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>653</th>\n",
       "      <td>01s</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>654</th>\n",
       "      <td>a03</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>655 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       0\n",
       "0     6S\n",
       "1    T03\n",
       "2    04b\n",
       "3    37A\n",
       "4    7.8\n",
       "..   ...\n",
       "650   Z0\n",
       "651   SH\n",
       "652  07A\n",
       "653  01s\n",
       "654  a03\n",
       "\n",
       "[655 rows x 1 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "path = r\"F:\\data\\dataware_house_base_se_fact_title_journal.csv\"\n",
    "df = pd.read_csv(path, header=None)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "e9f237b9-5983-4306-a04c-5db7d8722f8d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6S\n",
      "T3\n",
      "4B\n",
      "37A\n",
      "7_8\n",
      "C3\n",
      "A26\n",
      "D9\n",
      "A7\n",
      "2B\n",
      "U4\n",
      "6X\n",
      "I4\n",
      "B9\n",
      "G5\n",
      "2_3\n",
      "S9\n",
      "U1\n",
      "45B\n",
      "A8\n",
      "21A\n",
      "D12\n",
      "E1\n",
      "3A\n",
      "A12\n",
      "17A\n",
      "36B\n",
      "Z2\n",
      "3A\n",
      "E6\n",
      "12C\n",
      "3X\n",
      "A5\n",
      "Z10\n",
      "Z2\n",
      "1S\n",
      "T4\n",
      "Z8\n",
      "I6\n",
      "4A\n",
      "B7\n",
      "2_3\n",
      "25Z\n",
      "A28\n",
      "C9\n",
      "8Z\n",
      "S7\n",
      "A3\n",
      "A13\n",
      "6X\n",
      "A9\n",
      "Z13\n",
      "T6\n",
      "40B\n",
      "23A\n",
      "16X\n",
      "17X\n",
      "Z6\n",
      "J1\n",
      "9C\n",
      "12S\n",
      "X6\n",
      "X2\n",
      "5X\n",
      "9S\n",
      "SN\n",
      "F3\n",
      "5Z\n",
      "A23\n",
      "4Z\n",
      "5M\n",
      "3B\n",
      "Z3\n",
      "F2\n",
      "J7\n",
      "33X\n",
      "D1\n",
      "C6\n",
      "9B\n",
      "5M\n",
      "12M\n",
      "F1\n",
      "A50\n",
      "F2\n",
      "ZA\n",
      "A30\n",
      "YU\n",
      "S5\n",
      "C5\n",
      "A32\n",
      "20X\n",
      "32A\n",
      "A1\n",
      "B2\n",
      "9X\n",
      "G4\n",
      "X1\n",
      "H3\n",
      "A10\n",
      "F7\n",
      "T5\n",
      "12X\n",
      "A3\n",
      "1_2\n",
      "D8\n",
      "7C\n",
      "U11\n",
      "J0\n",
      "16Z\n",
      "8S\n",
      "21B\n",
      "0Z5\n",
      "22B\n",
      "14A\n",
      "19X\n",
      "39X\n",
      "0Z8\n",
      "24A\n",
      "27B\n",
      "A4\n",
      "Z5\n",
      "16B\n",
      "Z35\n",
      "S4\n",
      "Z7\n",
      "C7\n",
      "Z9\n",
      "ZK\n",
      "Z11\n",
      "13A\n",
      "E2\n",
      "A0\n",
      "B2\n",
      "Z12\n",
      "9X\n",
      "H4\n",
      "D1\n",
      "D9\n",
      "I8\n",
      "15B\n",
      "D0\n",
      "4M\n",
      "U6\n",
      "Z1\n",
      "F1\n",
      "F4\n",
      "11A\n",
      "5X\n",
      "E7\n",
      "I7\n",
      "1B\n",
      "Z5\n",
      "A8\n",
      "B6\n",
      "E8\n",
      "X2\n",
      "4M\n",
      "3_4\n",
      "2Z\n",
      "D7\n",
      "10M\n",
      "B49\n",
      "SK\n",
      "7X\n",
      "24X\n",
      "U2\n",
      "S3\n",
      "S2\n",
      "X3\n",
      "E8\n",
      "ZH\n",
      "34X\n",
      "43A\n",
      "5S\n",
      "F0\n",
      "17B\n",
      "D3\n",
      "26A\n",
      "Z3\n",
      "Z7\n",
      "B1\n",
      "5B\n",
      "1S\n",
      "7Z\n",
      "I0\n",
      "I9\n",
      "8A\n",
      "B0\n",
      "10Z\n",
      "7X\n",
      "ZG\n",
      "SQ\n",
      "28X\n",
      "D11\n",
      "G0\n",
      "3S\n",
      "47B\n",
      "A29\n",
      "0Z7\n",
      "S11\n",
      "6X\n",
      "5S\n",
      "S1\n",
      "23B\n",
      "47A\n",
      "E3\n",
      "ZC\n",
      "Z0\n",
      "4B\n",
      "10B\n",
      "T1\n",
      "1M\n",
      "Z9\n",
      "S5\n",
      "H9\n",
      "C12\n",
      "F4\n",
      "G1\n",
      "V0\n",
      "S8\n",
      "1C\n",
      "6M\n",
      "10C\n",
      "B3\n",
      "6C\n",
      "37X\n",
      "2X\n",
      "A22\n",
      "X10\n",
      "9Z\n",
      "7B\n",
      "C2\n",
      "43B\n",
      "8Z\n",
      "H7\n",
      "A12\n",
      "2M\n",
      "13Z\n",
      "B1\n",
      "C10\n",
      "Z4\n",
      "S3\n",
      "F8\n",
      "H8\n",
      "1A\n",
      "20A\n",
      "41B\n",
      "A1\n",
      "D3\n",
      "SM\n",
      "38B\n",
      "X5\n",
      "31X\n",
      "6Z\n",
      "3S\n",
      "3X\n",
      "20B\n",
      "A3\n",
      "22Z\n",
      "5Z\n",
      "7M\n",
      "30A\n",
      "11B\n",
      "H5\n",
      "A9\n",
      "C1\n",
      "ZJ\n",
      "F9\n",
      "19B\n",
      "36A\n",
      "SP\n",
      "33A\n",
      "42A\n",
      "E10\n",
      "X8\n",
      "A25\n",
      "18B\n",
      "2S\n",
      "2M\n",
      "G2\n",
      "6S\n",
      "38A\n",
      "40X\n",
      "6S\n",
      "3A\n",
      "44A\n",
      "F3\n",
      "7M\n",
      "B10\n",
      "SG\n",
      "2C\n",
      "ZI\n",
      "A34\n",
      "31B\n",
      "S\n",
      "4X\n",
      "1Z\n",
      "ZD\n",
      "SC\n",
      "10S\n",
      "D8\n",
      "2A\n",
      "6_7\n",
      "3C\n",
      "C1\n",
      "3B\n",
      "X1\n",
      "12Z\n",
      "46X\n",
      "B6\n",
      "G1\n",
      "A6\n",
      "18X\n",
      "A2\n",
      "S6\n",
      "41A\n",
      "7B\n",
      "A11\n",
      "9S\n",
      "1_4\n",
      "SL\n",
      "34A\n",
      "T2\n",
      "B7\n",
      "1B\n",
      "8X\n",
      "2B\n",
      "A8F\n",
      "B12\n",
      "SO\n",
      "X11\n",
      "A20\n",
      "C11\n",
      "E7\n",
      "S2\n",
      "17Z\n",
      "6A\n",
      "A9\n",
      "0Z2\n",
      "22M\n",
      "13B\n",
      "5C\n",
      "A60\n",
      "B6\n",
      "3_4\n",
      "A4\n",
      "40A\n",
      "Z3\n",
      "SF\n",
      "Z4\n",
      "X4\n",
      "B8\n",
      "G8\n",
      "D4\n",
      "8B\n",
      "4A\n",
      "0Z\n",
      "27X\n",
      "16A\n",
      "25B\n",
      "B11\n",
      "A0\n",
      "T11\n",
      "0Z6\n",
      "U10\n",
      "D2\n",
      "B4\n",
      "26X\n",
      "B3\n",
      "S6\n",
      "A1\n",
      "A5\n",
      "D4\n",
      "49X\n",
      "0Z3\n",
      "39B\n",
      "A27\n",
      "6M\n",
      "A31\n",
      "2X\n",
      "ZK\n",
      "A35\n",
      "D5\n",
      "33B\n",
      "26B\n",
      "T0\n",
      "7S\n",
      "3X\n",
      "S4\n",
      "15X\n",
      "F11\n",
      "3S\n",
      "U3\n",
      "E14\n",
      "35A\n",
      "J4\n",
      "12B\n",
      "A98\n",
      "Z8\n",
      "48B\n",
      "B8\n",
      "B5\n",
      "1_2\n",
      "44B\n",
      "ZF\n",
      "30X\n",
      "A4\n",
      "F5\n",
      "8M\n",
      "19A\n",
      "45X\n",
      "B5\n",
      "E12\n",
      "F5\n",
      "42B\n",
      "42X\n",
      "H2\n",
      "4_5\n",
      "19Z\n",
      "4B\n",
      "E6\n",
      "2A\n",
      "14X\n",
      "6A\n",
      "4S\n",
      "32X\n",
      "F7\n",
      "5A\n",
      "J5\n",
      "6B\n",
      "7A\n",
      "SI\n",
      "A74\n",
      "14B\n",
      "T12\n",
      "D6\n",
      "3Z\n",
      "F8\n",
      "A7\n",
      "ZB\n",
      "Z1\n",
      "Z25\n",
      "T8\n",
      "A11\n",
      "10X\n",
      "X5\n",
      "22A\n",
      "A19\n",
      "F6\n",
      "11C\n",
      "9M\n",
      "24M\n",
      "H12\n",
      "J6\n",
      "S8\n",
      "9M\n",
      "29X\n",
      "E5\n",
      "A18\n",
      "23X\n",
      "A33\n",
      "E5\n",
      "F9\n",
      "37B\n",
      "8B\n",
      "48A\n",
      "11M\n",
      "7Z\n",
      "SD\n",
      "X9\n",
      "H5\n",
      "X12\n",
      "B7\n",
      "S10\n",
      "K0\n",
      "D5\n",
      "5A\n",
      "T7\n",
      "G0\n",
      "3B\n",
      "9A\n",
      "JG\n",
      "8M\n",
      "SJ\n",
      "34B\n",
      "D6\n",
      "A24\n",
      "8S\n",
      "32B\n",
      "Z2\n",
      "SA\n",
      "8A\n",
      "U7\n",
      "H7\n",
      "1A2\n",
      "G7\n",
      "5_6\n",
      "9Z\n",
      "F12\n",
      "C0\n",
      "A16\n",
      "5B\n",
      "0Z4\n",
      "25A\n",
      "11Z\n",
      "0Z1\n",
      "H0\n",
      "10A\n",
      "D2\n",
      "S1\n",
      "B\n",
      "12A\n",
      "B4\n",
      "7C\n",
      "J2\n",
      "G3\n",
      "H6\n",
      "3M\n",
      "F6\n",
      "B22\n",
      "ZL\n",
      "0A\n",
      "B3\n",
      "9C\n",
      "38X\n",
      "6B\n",
      "Z5\n",
      "F5\n",
      "U5\n",
      "29A\n",
      "I1\n",
      "8S\n",
      "1H\n",
      "A2\n",
      "33Z\n",
      "T10\n",
      "2Z\n",
      "A17\n",
      "24B\n",
      "X3\n",
      "29B\n",
      "A0\n",
      "Z6\n",
      "Z7\n",
      "A15\n",
      "A1\n",
      "S12\n",
      "39A\n",
      "1Z\n",
      "20Z\n",
      "1_3\n",
      "A4\n",
      "8C\n",
      "15A\n",
      "S1\n",
      "Z1\n",
      "46A\n",
      "E2\n",
      "X\n",
      "2S\n",
      "A6\n",
      "G9\n",
      "E4\n",
      "9B\n",
      "X7\n",
      "35X\n",
      "11X\n",
      "B5\n",
      "1X\n",
      "41X\n",
      "E9\n",
      "23M\n",
      "2S\n",
      "15Z\n",
      "27A\n",
      "F4\n",
      "11S\n",
      "SE\n",
      "U4\n",
      "14Z\n",
      "ZM\n",
      "I5\n",
      "X4\n",
      "D7\n",
      "1_2\n",
      "A2\n",
      "8X\n",
      "X6\n",
      "U9\n",
      "A14\n",
      "U12\n",
      "C8\n",
      "Z1\n",
      "H1\n",
      "AS1\n",
      "4C\n",
      "S2\n",
      "5X\n",
      "6Z\n",
      "A5\n",
      "C0\n",
      "5B\n",
      "C0\n",
      "13X\n",
      "18A\n",
      "ZE\n",
      "A0\n",
      "9A\n",
      "A7\n",
      "E0\n",
      "2A\n",
      "Z24\n",
      "B9\n",
      "45A\n",
      "50X\n",
      "A10\n",
      "2B\n",
      "E11\n",
      "3Z\n",
      "J3\n",
      "5C\n",
      "4Z\n",
      "46B\n",
      "1X\n",
      "35B\n",
      "7S\n",
      "1B\n",
      "F10\n",
      "S0\n",
      "30B\n",
      "E13\n",
      "A21\n",
      "SB\n",
      "1A\n",
      "Z5\n",
      "4X\n",
      "D10\n",
      "4S\n",
      "C4\n",
      "U8\n",
      "31A\n",
      "28A\n",
      "S3\n",
      "Z9\n",
      "A36\n",
      "E1\n",
      "7B\n",
      "28B\n",
      "7A\n",
      "6A\n",
      "Z0\n",
      "SH\n",
      "7A\n",
      "1S\n",
      "A3\n"
     ]
    }
   ],
   "source": [
    "for value in df.iloc[:, 0]:  # df.iloc[:, 0] 获取第0列\n",
    "    print(deal_num(value))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5294164c-1a9e-437f-86a2-284c8a92e850",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
